/*
 * Copyright 2013 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package jim.h.commons;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

/**
 * @author jinggang.huangjg 2013-1-8 下午7:46:39
 */
public class OJdbcTest {

    public static void main(String[] args) throws SQLException {
        DataSource dataSource = createDataSource();
        Connection conn = null;
        PreparedStatement pstm = null;
        ResultSet rs = null;
        try {
            conn = dataSource.getConnection();
            pstm = conn.prepareStatement("select * from weight_tariff t where t.id = 10641");
            rs = pstm.executeQuery();
            while (rs.next()) {
                System.out.println("id: " + rs.getObject("id").getClass());
                System.out.println("first_weight_fee: " + rs.getObject("first_weight_fee").getClass());
                System.out.println("is_default: " + rs.getObject("is_default").getClass());
            }
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (pstm != null) {
                    pstm.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
            }
        }
    }

    private static DataSource createDataSource() {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        ds.setUsername("alibaba");
        ds.setPassword("ccbutest");
        ds.setUrl("jdbc:oracle:thin:@10.20.36.19:1521:ocntest");
        ds.setInitialSize(1);
        return ds;
    }
}
